<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>网上书店</title>

		<link rel="stylesheet" href="css/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="css/style.css">
		<script src="js/app.js" charset="UTF-8"></script>
		<script src="js/vue.js"></script>
		<script src="js/axios.min.js"></script>
		<script src="js/vue-cookies.js"></script>
		<script src="css/layui/layui.js" charset="utf-8"></script>
		<!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
	</head>
	<body>

		<div id="app">
	<ul class="layui-nav">
				<li class="layui-nav-item">
					<a href="index.html">主页</a>
				</li>
			
			<li  v-show="!loginflag" class="layui-nav-item" style="margin-left: 400px;">
				<a href="javascript:void(0);" @click="loginplease">{{userShowName}}</a>
			</li>
				<li  v-show="loginflag" class="layui-nav-item" style="margin-left: 400px;">
					<a href="javascript:void(0);" @click="loginplease">{{userShowName}}</a>
					<dl class="layui-nav-child">
						<dd> <a href="user.html">个人中心</a></dd>
						<dd><a href="javascript:void(0);" onclick="clearAllCookie()">注销</a></dd>
					</dl>
				</li>
				<li v-show="loginflag" class="layui-nav-item">
					<a href="order.html">我的订单</a>
					<dl class="layui-nav-child">
						<dd><a href="HistoryOrder.html">历史订单</a></dd>
					</dl>
				</li>
				<li v-show="loginflag" class="layui-nav-item">
					<a href="shoppingcart.html">购物车<span class="layui-badge">{{shoppingcartnumber}}</span></a>
				</li>
				<li v-show="$cookies.get('userType')==1" class="layui-nav-item">
					<a href="myShop.html">创建商品</a>
					<dl class="layui-nav-child">
						<dd><a href="myShopOrder.html">商家订单</a></dd>
					</dl>
				</li>
			</ul>
			<div v-if="haveShop">
				<div>{{shop}}</div>
			</div>
			<div v-if="!haveShop">
				查无此店

			</div>
		</div>





		<script type="text/javascript">
			var vm = new Vue({
				el: '#app',
				data: {
					haveShop: true,
					username: '请登录',
					loginflag: false,
					shoppingcartnumber: 0,
					shop: null,
				},
				filters: {
					keepTwoNum: function(value) {
						value = Number(value)
						return value.toFixed(2)
					}
				},
				methods: {
					loginplease: function() {
						if (this.loginflag)
							window.location.href = 'user.html'; //跳转主页
						else
							window.location.href = 'login.html'; //跳转主页
					},
					ShopSelect: function(shopId) {
						console.log(URL + '/shop/shop')
						console.log(shopId)
						if (!shopId)
							window.location.href = 'index.html';
						else
							axios.get(URL + '/shop/shop', { //params参数必写 , 如果没有参数传{}也可以
								params: {
									shopId: shopId,

								}
							})
							.then(function(response) {
								if (response.data.code == 1) {
									console.log(response)
									vm.shop = response.data.result


								} else if (response.data.code == 0) {
									vm.haveShop = false
									console.log(response)
									console.log(response.data.msg)

								}
							})
							.catch(function(error) {
								console.log(error);
							});

					},

				},

				created: function() {
					// checklogin()
					checklogin()

				},
				mounted: function() {
					if ($cookies.get("userName") != null)
						this.username = $cookies.get("userName")
					this.loginflag = $cookies.get("loginflag")
					console.log(getQueryVariable("shopId"))
					this.ShopSelect(getQueryVariable("shopId"))

				}


			})
		</script>


		<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
		<script>
			layui.use('element', function() {
				var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块

				//监听导航点击
				element.on('nav(demo)', function(elem) {
					//console.log(elem)
					layer.msg(elem.text());
				});
			});
		</script>

	</body>
</html>
